<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="../../../common/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<sfa:mainTitle></sfa:mainTitle>
		<%@ include file="../../../common/meta.jsp"%>
		<link rel="stylesheet" href="${path }/css/affixUpload.css"
			type="text/css"></link>
		<script type="text/javascript"
			src="${path}/script/lhgdialog/lhgdialog.min.js">
</script>
		<script type="text/javascript" src="${path}/script/affixUpload.js">
</script>

		<script type="text/javascript">
$(function() {
	//初始化控件 --1
	var actionPath = "${path}/affix/index/upload/SALEPRODUCT";
	var div = 'sfaUpload'
	sfaUpload.init(actionPath, div);

	//设置表单验证
	var add = $("#add").validate( {
		rules : {
			trainType : {
				required : true
			},
			trainBranchid : {
				required : true
			},
			trainItem : {
				required : true,
				rangelength : [ 2, 20 ]
			},
			SALETRAINERID : {
				required : true
			},
			applyStartDate :{
				required : true
			},
			applyEedDate :{
				required : true
			},
			trainStratDate :{
				required : true
			},
			trainEndDate :{
				required : true
			},
		}
	});
	$("#trainBranchid")
			.change(
					function() {
						var url = '${path }/productandtrain/lecturer/index/getTrainerByBranchId?r=' + Math
								.random();
						var data = {
							branchId : $(this).val()
						};
						$
								.ajax( {
									url : url,
									data : data,
									success : function(result) {
										var obj = eval('(' + result + ')');
										var selStr = "";
										for ( var i = 0; i < obj.trainerList.length; i++) {
											selStr += "<option value='"
													+ obj.trainerList[i].saleTrainerId
													+ "'>"
													+ obj.trainerList[i].trainerName
													+ "</option>";
										}
										$("#SALETRAINERID").html(selStr);
									}
								});
					});
	$("#trainBranchid").change();

	$("#btn_submit")
			.click(function() {
				if (sfaUpload.getIsUploading()) {
					art.dialog( {
						content : "文件正在上传,请先取消上传文件！",
						lock : true,
						ok : true
					});
					return;
				}
				//debugger;
				var saletrantakeid = '${saletrantakeid}';
				
				var traintype = $("#trainType").val(); //培训类型
				var trainbranchid = $("#trainBranchid").val(); //培训机构
				var trainitem = $("#trainItem").val(); //培训标题
				var saletrainerid = $("#SALETRAINERID").val(); //选择讲师
				var traincontent = $("#trainContent").val(); //培训内容
					
				var applyStartDate = $("#applyStartDate").val(); //报名开始时间
				var applyEndDate = $("#applyEndDate").val(); //报名结束时间
				var trainStartDate = $("#trainStartDate").val(); //报名开始时间
				var trainEndDate = $("#trainEndDate").val(); //报名开始时间
				var maxApplyCount = $("#maxApplyCount").val(); //最大报名人数
				//alert(saletrantakeid);
				var affixStr = "";
				$(".uoloadedFile").each(
						function(i, o) {
							var obj = $(o);
							affixStr += obj.attr("SALEAFFIXITEMID") + ";"
									+ obj.attr("isDel") + ";;";
						});

				var productStr = "";
				$(".spItem").each(function(i, obj) {
					productStr += $(obj).attr("spid") + ";;;;;;;;;";
				});
				var data = {
				saletrantakeid :saletrantakeid,
					trainType : traintype,
					trainBranchid : trainbranchid,
					trainItem : trainitem,
					saletrainerid : saletrainerid,
					trainContent : traincontent,
					
					applyStartDate : applyStartDate,
					applyEndDate : applyEndDate,
					trainStartDate : trainStartDate,
					trainEndDate : trainEndDate,
					maxApplyCount : maxApplyCount,	
					productStr : productStr,
					affixStr : affixStr
				};
				$.ajax( {
					url : "${path}/productandtrain/lecturer/index/update",
					type : "POST",
					timeout : 10000,
					data : data,
					success : function(result) {
							result = '(' + result + ')';
								var obj = eval(result);
								if (obj.result == true) {
									art.dialog( {
												icon : "succeed",
												content : obj.message,
												lock : true,
												ok : function() {
													window.location.href = "${path}/productandtrain/lecturer/index";
												}
											});
								} else {
									art.dialog( {
										icon : "error",
										content : obj.message,
										lock : true,
										ok : true
									});
								}
							}
						});
			});
});
function opendialog() {
	$.dialog( {
		title : '产品关联',
		lock : true,
		background : '#FFF',
		opacity : 0.1,
		max : false,
		min : false,
		width : '650px',
		height : '550px',
		content : 'url:${path}/productandtrain/product/index/salepro'
	});
}

function addProducts(productList) {
	var list = $.dialog.list;
	for ( var i in list) {
		list[i].close();
	}

	var productArray = productList.split(";;;;;;;;;");
	$(productArray)
			.each(
					function(i, obj) {
						if (obj) {
							var productInfo = obj.split(";;;;;");

							var productId = productInfo[0];
							var tag = true;

							$(".spItem").each(function(i, obj) {
								if ($(obj).attr("spid") == productId) {
									tag = false;
								}
							});
							if (tag) {
								var spItem = $("<div class=\"spItem\" spid=\""
										+ productId + "\"></div>");
								spItem.append($("<span>" + productInfo[1]
										+ "</span>"));
								spItem
										.append($("<a href=\"javascript:void(0)\" onclick=\"delItem(this)\">&nbsp;x</a>"));
								$("#productsDiv").append(spItem);
							}
						}

					});
}

function delItem(obj) {
	$(obj).parent().remove();
}
</script>
	</head>
	<body id="master">
		<sfa:mainHeader></sfa:mainHeader>
		<div class="main">
			<div class="webpart3 contentarea">
				<div class="webpart-head">
					<div class="webpart-head-item">
						新建培训
					</div>
				</div>
				<div class="webpart-main">
					<div class="webpart-main-item" style="padding: 30px;">
						<div class="d_formitem">
							<form id="add">
								<table cellspacing="0" cellpadding="0" class="formitem">
									<tr>
										<td width="15%">
											<span>培训类型：</span>
										</td>
										<td>
											<sfa:dic showType="select" kindNo="TRAINTYPE"
												attr="class='input-txt'" name="trainType" id="trainType" ></sfa:dic>

										</td>
									</tr>
									<tr>
										<td>
											<span>培训机构：</span>
										</td>
										<td>
											<select class="input-txt" name="trainBranchid"
												id="trainBranchid">
												<c:forEach items="${BranchList}" var="branch">

													<option value="${branch.branchId }"
														<c:if test="${train.trainBranchid==branch.branchId }">selected='selected'</c:if>>
														${branch.branchName}

													</option>
												</c:forEach>
											</select>
										</td>
									</tr>
									<tr>
										<td>
											<span>培训标题：</span>
										</td>
										<td>
											<input type="text" id="trainItem" name="trainItem"
												class="input-txt" maxlength="20" value="${train.trainItem}" />
										</td>
									</tr>
									<tr>
										<td>
											<span>选择讲师：</span>
										</td>
										<td>
											<select class="input-txt" id="SALETRAINERID"
												style="width: 120px;" name="SALETRAINERID" value="${train.saleTrainerName}">
												
											</select>
										</td>
									</tr>
									<tr>
										<td>
											<span>培训内容：</span>
										</td>
										<td>
											<textarea name="affairContent"
												style="width: 300px; height: 80px;" id="trainContent"
												name="trainContent" class="" value="">${train.trainContent}</textarea>
										</td>
									</tr>
									<tr>
										<td>
											报名开始时间:
										</td>
										<td>
											<div id="markDiv">
												<input id="applyStartDate" name="applyStartDate"
													onfocus="WdatePicker({startDate:'%y-%M-01 00:00',dateFmt:'yyyy-MM-dd HH:mm',alwaysUseStartDate:true})"
													readOnly="true" class="Wdate inputbox"
													value="${train.applyStartDate}" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											报名结束时间:
										</td>
										<td>
											<div id="markDiv">
												<input id="applyEndDate" name="applyEndDate"
													onfocus="WdatePicker({startDate:'%y-%M-01 00:00',dateFmt:'yyyy-MM-dd HH:mm',alwaysUseStartDate:true})"
													readOnly="true" class="Wdate inputbox"
													value="${train.applyEndDate}" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											培训开始时间:
										</td>
										<td>
											<div id="markDiv">
												<input id="trainStartDate" name="trainStartDate"
													onfocus="WdatePicker({startDate:'%y-%M-01 00:00',dateFmt:'yyyy-MM-dd HH:mm',alwaysUseStartDate:true})"
													readOnly="true" class="Wdate inputbox"
													value="${train.trainStartDate}" "/>
											</div>
										</td>
									</tr>
									<tr>
										<td>

											培训结束时间:
										</td>
										<td>
											<div id="markDiv">
												<input id="trainEndDate" name="trainEndDate"
													onfocus="WdatePicker({startDate:'%y-%M-01 00:00',dateFmt:'yyyy-MM-dd HH:mm',alwaysUseStartDate:true})"
													readOnly="true" class="Wdate inputbox"
													value="${train.trainEndDate}" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											最大报名人数：
										</td>
										<td>
											<input type="text" id="maxApplyCount" name="maxApplyCount"
												class="input-txt" maxlength="20"
												value="${train.maxApplyCount}" />
										</td>
									</tr>
									<tr>
										<td>
											培训课件:
										</td>
										<td>


											<div class="">

												<div id="fileList">
												
														<c:forEach items="${affixList}" var="affixItem">
															<div class="uoloadedFile" isDel="n"
																AFFIXPATH="${affixItem.SALEAFFIXITEMFILEPATH}"
																FILENAME="${affixItem.SALEAFFIXITEMFILENAME}"
																 SALEAFFIXITEMID="${affixItem.SALEAFFIXITEMID}">
																<span>${affixItem.SALEAFFIXITEMFILENAME}</span>
																	<a href="javascript:void(0)"
															onclick="sfaUpload.delUpload(this)">&nbsp;删除</a>
															</div>
														</c:forEach>
												
												</div>
												<div id="sfaUpload"></div>
											</div>


											<input type="hidden" id="AFFIXPATH" name="AFFIXPATH" />
										</td>
									</tr>
									<tr>
										<td>
											相关产品
										</td>

										<td>
											<div id="productsDiv">
											
											</div>
											<a href="#" onclick="opendialog()">修改</a>
										</td>
									</tr>
									<tr>
										<th>
										</th>
										<td>
											<input type="button" id="btn_submit" tabindex="5"
												class="linkbtn2" value="提交">
											&nbsp;&nbsp;
											<input type="button" id="btn_back" tabindex="5"
												class="linkbtn2" value="返回"
												onclick="location.href='${path}/productandtrain/lecturer/index';">
										</td>
									</tr>
								</table>
							</form>
						</div>
					</div>
				</div>
				<div class="webpart-foot">
					<div class="webpart-foot-item">
					</div>
				</div>
			</div>
		</div>
		<sfa:mainFooter></sfa:mainFooter>
	</body>
</html>